package com.skvalex.transport.map;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import com.skvalex.transport.vehicle.VehicleTracker;
import com.google.android.maps.MapView;

/**
 * User: alexey.emelyanenko@gmail.com
 * Date: 4/15/12 1:36 AM
 *
 * Modified by skvalex@gmail.com
 */
public class ExtendedMapView extends MapView {

    private int oldZoomLevel = -1;
    private VehicleTracker vehicleTracker;

    public ExtendedMapView(Context context, String apiKey) {
        super(context, apiKey);
    }

    public ExtendedMapView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ExtendedMapView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void setVehicleTracker(VehicleTracker vehicleTracker) {
        this.vehicleTracker = vehicleTracker;
    }

    @Override
    public void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        if (getZoomLevel() != oldZoomLevel) {
            oldZoomLevel = getZoomLevel();
            vehicleTracker.syncVehicles(true);
        }
    }
}
